//Page Object
import { request } from "../../request/index.js";
Page({
  data: {
    //轮播图数组
    swiperList:[],
    //导航数组
    catesList:[],
    //楼层数组
    floorList:[]
    
  },
  //页面开始加载就会触发
  onLoad: function(options) {
    // 1 发送异步请求获得轮播图数据
    // var reqTask = wx.request({
    //   url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
    //   success: (result) => {
    //     this.setData({
    //       swiperList:result.data.message
    //     })
        
    //   }
    // });
    this.getSwiperList();
    this.getCatesList();
    this.getFloorList();      
  },

  //获取轮播图数据
  getSwiperList(){
  request({url:"/home/swiperdata"})
    .then(result=>{
      result.forEach((v,i)=>{result[i].navigator_url=v.navigator_url.replace('main','index');});
      this.setData({
        swiperList:result
      })
    })
  },

  //获取分类导航数据
  getCatesList(){
    request({url:"/home/catitems"})
      .then(result=>{
        this.setData({
          catesList:result
        })
      })
    },

  //获取楼层数据
  getFloorList(){
    request({url:"/home/floordata"})
      .then(result=>{
        for(let k=0;k<result.length;k++){
          result[k].product_list.forEach((v,i)=>{
            result[k].product_list[i].navigator_url=v.navigator_url.replace('?','/index?');
          });
        }
        this.setData({
          floorList:result
        })
      })
  },

  // //获取楼层数据
  // getFloorList(){
  //   request({url:"/home/floordata"})
  //     .then(result=>{
  //       this.setData({
  //         floorList:result
  //       })
  //     })
  // },

  onReady: function() {
    
  },
  onShow: function() {
    
  },
  onHide: function() {

  },
  onUnload: function() {

  },
  onPullDownRefresh: function() {

  },
  onReachBottom: function() {

  },
  onShareAppMessage: function() {

  },
  onPageScroll: function() {

  },
  //item(index,pagePath,text)
  onTabItemTap:function(item) {

  }
});
  